package com.prd.controller;


import com.prd.dto.CustomerRemarkDTO;
import com.prd.service.CustomerRemarkService;
import com.prd.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 客户-备注总表 前端控制器
 * </p>
 *
 * @author o1
 * @since 2023-11-24
 */
@Api(tags={"客户管理-新增各种备注"})
@RestController
@RequestMapping("/api/customerRemark")
public class CustomerRemarkController {

    private CustomerRemarkService remarkService;

    public CustomerRemarkController(CustomerRemarkService remarkService) {
        this.remarkService = remarkService;
    }

    @ApiOperation("客户模块-UNI-新增备注，备注: 客户备注1，项目备注2，客户需求备注3，客户分析4，销售/业务-策略/方案5，销售/业务-计划/实施6")
    @PostMapping(value = "uAdd", produces = "application/json;charset=UTF-8")
    public JsonData uAdd(
            @ApiParam(value = "uAdd") @RequestBody CustomerRemarkDTO remarkDTO) {
        return remarkService.uAdd(remarkDTO);
    }

    @ApiOperation("客户模块-UNI-查询备注列表")
    @GetMapping("uSearch")
    public JsonData uSearch(
            @ApiParam(value = "当前页数") @RequestParam(value = "page", defaultValue = "1") int page,
            @ApiParam(value = "当页数目") @RequestParam(value = "size", defaultValue = "10") int size,
            @ApiParam(value = "备注类型") @RequestParam(value = "type", defaultValue = "-1") int type,
            @ApiParam(value = "项目id") @RequestParam(value = "projectId", defaultValue = "") String projectId,
            @ApiParam(value = "客户编号") @RequestParam(value = "customerNo", defaultValue = "") String customerNo) {
        Map<String,Object> remarkList =  remarkService.uSearch(page, size, type, projectId, customerNo);
        return JsonData.buildSuccess(remarkList);
    }

    @ApiOperation("客户模块-UNI-移除备注")
    @GetMapping("uRemove")
    public JsonData uRemove(
            @ApiParam(value = "id") @RequestParam(value = "id", defaultValue = "-1") int id
    ) {
        if (remarkService.removeById(id))
            return JsonData.buildSuccess();
        else
            return JsonData.buildError("请检查id");
    }
}

